package com.kdzy.lshy.socity_server.common;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;

/**
 * 分页请求处理
 */
public class RequestConver {
    public static HttpServletRequest getRequestPayload(HttpServletRequest request){
        StringBuilder sb = new StringBuilder();
        try{
            BufferedReader reader = request.getReader();
            char[]buff = new char[1024];
            int len;
            while((len = reader.read(buff)) != -1) {
                sb.append(buff,0, len);
            }
            if(!sb.toString().equals(null)&&!sb.toString().equals("")){
                String[] arg1=sb.toString().split("&");
                String page=arg1[0].split("=")[1];
                String rows=arg1[1].split("=")[1];
                request.setAttribute("offset",page);
                request.setAttribute("limit",rows);
                return request;
            }
        }catch (IOException e) {
            e.printStackTrace();
        }
        return request;
    }
}
